<template>
  <div>
    <div>
      <div class="index_search">
        <div @click="goBack" class="go_back">
          <span class="iconfont icon-icon4"></span>
        </div>
        <div class="search_content">
          <div>
            <input type="text" v-model="inputValue" @input="searchGo()" placeholder="请输入关键词">
          </div>
          <div class="chahao">
            <span @click="chaHao" v-if="searchOrCancel === true" class="iconfont icon-chahao"></span>
          </div>
        </div>
        <div class="go_del">
          <span v-if="searchOrCancel === false" @click="goBack">取消</span>
          <span v-else @click="searchResult()">搜索</span>
        </div>
      </div>
    </div>
    <div class="search_center">
      <div v-if="searchOrResult === false">
        <SearchContent ref="history" :historyName="historyName"></SearchContent>
      </div>
      <div v-else>
        <div>12345</div>
      </div>
    </div>
  </div>
</template>

<script>
  import SearchContent from './Search'
  import {saveVideoSearch} from '../../assets/js/cache'  //引用本地存储js
  export default {
    name: 'VideoSearch',
    data() {
      return {
        inputValue: '',
        searchOrCancel: false,
        searchOrResult: false,
        historyName:'video_search'
      }
    },
    created() {

    },
    methods: {
      goBack() {
        this.$router.push({name: 'Index'});
        this.searchOrResult = false;
      },
      //判断input有没有值 切换 取消 与搜索按钮
      searchGo() {
        if (this.inputValue !== '') {
          this.searchOrCancel = true
        } else {
          this.searchOrCancel = false
        }

      },
      //搜索按钮
      searchResult() {
        saveVideoSearch(this.inputValue);
        this.searchOrResult = true;
        this.$refs.history.getHistoryTitle();
        // console.log(this.$store.state.searchHistort.searchType)
      },
      //叉号
      chaHao() {
        this.inputValue = '';
        this.searchGo();
      }
    },
    components: {
      SearchContent
    }

  }
</script>

<style scoped>
  #indexSearch {
    border: none;
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    background-color: #f8f8f8;
  }

  .index_search {
    height: 40px;
    background-color: #ffffff;
    padding: 0.5rem;
    display: flex;
    display: -webkit-flex; /* Safari */
    flex-direction: row;
    flex-wrap: nowrap;
    line-height: 40px;
    color: #333333;
    width: calc(100% - 20px);
  }

  .index_search .go_back {
    margin-right: 10px;
  }

  .index_search .search_content {
    background-color: #f8f8f8;
    border-radius: 0.5rem;
    /*width: 80%;*/
    display: flex;
    padding: 0 0.5rem;
    justify-content: space-between;
    width: 100%;
  }

  .go_del {
    width: 3rem;
    text-align: center;
  }

  .index_search .search_content > div:nth-child(1) {

  }

  /*.index_search .search_content > div:nth-child(2) {*/
    /*!*width: 45%;*!*/
    /*!*flex: 3;*!*/
  /*}*/

  /*.index_search .search_content > div:nth-child(3) {*/

  /*}*/

  .index_search .search_content input {
    width: 100%;
    border: none;
    outline: none;
    /*border-left: 1px solid #dcdcdc;*/
    background-color: #f8f8f8;
  }

  .index_search .search_content .chahao {
    color: #999;
  }
</style>
